package com.andriod.waker;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

public class My_TextEdit implements TextWatcher{

	private CharSequence temp;
    private int selectionStart;
    private int selectionEnd;
    private EditText own_et;
    
	public My_TextEdit(EditText et) {

		own_et = et;
		own_et.addTextChangedListener(this);
		own_et.setSingleLine(true);
	}
	
    public void onTextChanged(CharSequence s, int start, int before,
    int count) {
    	temp = s;
    }

    public void beforeTextChanged(CharSequence s, int start, int count,
    int after) {
    }

    public void afterTextChanged(Editable s) {
    	selectionStart = own_et.getSelectionStart();
    	selectionEnd = own_et.getSelectionEnd();

    	if (temp.length() > 2) {
    				 
    		s.delete(selectionStart - 1, selectionEnd);
    		int tempSelection = selectionStart;
    		own_et.setText(s);
    		own_et.setSelection(tempSelection);
    	}
    }
    
    public EditText Get_et()
    {
    	return own_et;
    }
}
